let lastJsUrl = [];
const autoRefresh = async () => {
  const rsp = await fetch("/?timestamp=" + Date.now()).then((rsp) =>
    rsp.text()
  );

  const result = rsp.match(/\<script[^\>]+\>/gi);

  if (!result) return;
  const jsUrl = result.map((item) => {
    return item.match(/src\=['"]([^'"]*)["']/i)?.[1];
  });
  if (lastJsUrl.length > 0) {
    const compareResult = jsUrl.every((url) => {
      return lastJsUrl.includes(url);
    });
    if (!compareResult) {
      window.location.reload();
    }
  } else {
    lastJsUrl = [...jsUrl];
  }
};
setInterval(() => {
  autoRefresh();
}, 5000);
